from django.shortcuts import render
from django.shortcuts import render_to_response
from django.shortcuts import HttpResponse
from web_models import models
import json

# Create your views here.
def file_upload(request):

    if request.method == "POST":
        f = request.FILES['files[]']
        filename = f._name
        minetype = f.content_type
        filepath = 'static/' + filename
        destination = open(filepath, 'wb+')
        for chunk in f.chunks():
            destination.write(chunk)
        destination.close()
        HttpResponse(
            json.dumps({"files": [{"name": filename, "minetype": minetype}]})
        )
    else:
        return render_to_response("file_upload.html")

def webserver(request):
    data = {}
    servers = models.WebServer.objects.all()
    data["servers"] = servers

    return render_to_response("webserver.html",data)









